﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WumpusTest
{
	class Map
	{
		private static Cave cave;

		private int playerOrigin;
		private int playerLocation;
		private int wumpusLocation;
		private int bermudaTriangleRoom;
		private int marianasTrenchRoom;
		private int krakenRoom;
		private int cthululuRoom;
		public Map()
		{
			cave = new Cave();
		}
		public int PlayerOrigin
		{
			get { return playerOrigin; }
			set { playerOrigin = value; }
		}

		public int PlayerLocation
		{
			get { return playerLocation; }
			set { playerLocation = value; }
		}
		public int WumpusLocation
		{
			get { return wumpusLocation; }
			set { wumpusLocation = value; }
		}
		public int BermudaTriangleRoom
		{
			get { return bermudaTriangleRoom; }
			set { bermudaTriangleRoom = value; }
		}
		public int MarianasTrenchRoom
		{
			get { return marianasTrenchRoom; }
			set { marianasTrenchRoom = value; }
		}
		public int KrakenRoom
		{
			get { return krakenRoom; }
			set { krakenRoom = value; }
		}
		public int CthuluRoom
		{
			get { return cthululuRoom; }
			set { cthululuRoom = value; }
		}

		private int[] RandomRoomArray()
		{
			int[] randomArray = new int[30];

			for (int index = 0; index < 30; index++)
			{
				randomArray[index] = index + 1;
			}

			Random randomNum = new Random();
			for (int index = randomArray.Length; index > 1; index--)
			{
				int counter = randomNum.Next(index);
				int temporary = randomArray[counter];
				randomArray[counter] = randomArray[index - 1];
				randomArray[index - 1] = temporary;
			}
			return randomArray;
		}
		public void startingLocation()
		{
			int[] randomArray = RandomRoomArray();
			PlayerLocation = randomArray[0];
			playerOrigin = randomArray[0];
			krakenRoom = randomArray[1];
			cthululuRoom = randomArray[2];
			marianasTrenchRoom = randomArray[3];
			bermudaTriangleRoom = randomArray[4];
			wumpusLocation = randomArray[5];
		}
		public void meetBat(int batNumber)
		{
			int[] randomArray = RandomRoomArray();
			if (batNumber == 1)
			{
				for (int index = 0; index < 30; index++)
				{
					if (krakenRoom != randomArray[index] && cthululuRoom != randomArray[index]
						&& marianasTrenchRoom != randomArray[index] && wumpusLocation != randomArray[index]
						&& bermudaTriangleRoom != randomArray[index])
					{
						krakenRoom = randomArray[index];
						break;
					}
				}
				for (int index = 0; index < 30; index++)
				{
					if (krakenRoom != randomArray[index] && cthululuRoom != randomArray[index]
						&& marianasTrenchRoom != randomArray[index] && wumpusLocation != randomArray[index]
						&& bermudaTriangleRoom != randomArray[index])
					{
						PlayerLocation = randomArray[index];
						break;
					}
				}
			}
			else
			{
				for (int index = 0; index < 30; index++)
				{
					if (krakenRoom != randomArray[index] && cthululuRoom != randomArray[index]
						&& marianasTrenchRoom != randomArray[index] && wumpusLocation != randomArray[index]
						&& bermudaTriangleRoom != randomArray[index])
					{
						PlayerLocation = randomArray[index];
					}
				}
			}
		}
		public void moveOutOfPits()
		{
			PlayerLocation = playerOrigin;
		}
		public bool[] hazard()
		{
			bool[] hazards = new bool[3];
			if (krakenRoom == cave.CaveSystem[playerLocation].NorthWest || krakenRoom == cave.CaveSystem[playerLocation].NorthEast ||
				krakenRoom == cave.CaveSystem[playerLocation].East || krakenRoom == cave.CaveSystem[playerLocation].SouthEast ||
				krakenRoom == cave.CaveSystem[playerLocation].SouthWest || krakenRoom == cave.CaveSystem[playerLocation].West ||
				cthululuRoom == cave.CaveSystem[playerLocation].NorthWest || cthululuRoom == cave.CaveSystem[playerLocation].NorthEast ||
				cthululuRoom == cave.CaveSystem[playerLocation].East || cthululuRoom == cave.CaveSystem[playerLocation].SouthEast ||
				cthululuRoom == cave.CaveSystem[playerLocation].SouthWest || cthululuRoom == cave.CaveSystem[playerLocation].West)
			{
				hazards[0] = true;
			}
			if (marianasTrenchRoom == cave.CaveSystem[playerLocation].NorthWest || marianasTrenchRoom == cave.CaveSystem[playerLocation].NorthEast ||
				marianasTrenchRoom == cave.CaveSystem[playerLocation].East || marianasTrenchRoom == cave.CaveSystem[playerLocation].SouthEast ||
				marianasTrenchRoom == cave.CaveSystem[playerLocation].SouthWest || marianasTrenchRoom == cave.CaveSystem[playerLocation].West ||
				bermudaTriangleRoom == cave.CaveSystem[playerLocation].NorthWest || bermudaTriangleRoom == cave.CaveSystem[playerLocation].NorthEast ||
				bermudaTriangleRoom == cave.CaveSystem[playerLocation].East || bermudaTriangleRoom == cave.CaveSystem[playerLocation].SouthEast ||
				bermudaTriangleRoom == cave.CaveSystem[playerLocation].SouthWest || bermudaTriangleRoom == cave.CaveSystem[playerLocation].West)
			{
				hazards[1] = true;
			}
			if (wumpusLocation == cave.CaveSystem[playerLocation].NorthWest || wumpusLocation == cave.CaveSystem[playerLocation].NorthEast ||
				wumpusLocation == cave.CaveSystem[playerLocation].East || wumpusLocation == cave.CaveSystem[playerLocation].SouthEast ||
				wumpusLocation == cave.CaveSystem[playerLocation].SouthWest || wumpusLocation == cave.CaveSystem[playerLocation].West)
			{
				
				hazards[2] = true;
			}
			else
			{
				for (int counter = 0; counter < 3; counter++)
				{
					
					hazards[counter] = false;
				}
			}
			return hazards;
		}
		public bool isWumpusAlive;
		public bool ShootArrow()
		{
		    int arrowTarget = GameControl.ShootAnArrow();

		    if (arrowTarget == wumpusLocation)
		    {
		        isWumpusAlive = false;
		    }
		    return isWumpusAlive;
		}
		public void movingWumpus()
		{
			

			cave.GetRoomInfo(playerLocation);

			
			Random amountWumpusMoves = new Random();

			for (int moves = amountWumpusMoves.Next(2, 4); moves > 0; moves--)
			
			{
				int result = 1;
				while (result != -1)
				{
					Random rnd = new Random();
					if (rnd.Equals(1))
					{
						result = cave.CaveSystem[wumpusLocation].NorthEast;
					}
					else if (rnd.Equals(2))
					{
						result = cave.CaveSystem[wumpusLocation].NorthWest;
					}
					else if (rnd.Equals(3))
					{
						result = cave.CaveSystem[wumpusLocation].East;
					}
					else if (rnd.Equals(4))
					{
						result = cave.CaveSystem[wumpusLocation].West;
					}
					else if (rnd.Equals(5))
					{
						result = cave.CaveSystem[wumpusLocation].SouthWest;
					}
					else
					{
						result = cave.CaveSystem[wumpusLocation].SouthEast;
					}
				}

				wumpusLocation = result;
			}
		}


	}
}
